﻿package smooth.core.object.googleMapCanvasComponent {
	
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.display.Shape;
	import flash.events.MouseEvent;
	import flash.events.TouchEvent;
	import flash.geom.Point;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	import flash.text.AntiAliasType;
	import caurina.transitions.Tweener;	
	import smooth.core.object.flickrComponent.FlickrComponent;
	import flash.display.Bitmap;
	import flash.display.Loader;
	import flash.events.Event;
	import flash.net.URLRequest;
	
	public class PhysicalMapButtonComponent extends Sprite {
		
		[Embed(source="Arial.ttf", fontFamily="myFont")] 
		public var myFont:Class;
		
		public var initialPosX:int;
		public var initialPosY:int;
		private var canvas:Object;
		private var t:TextField;
		private var arrangeIndex:int = 0;
		private var clickgrabber:Shape = new Shape();	
		
		public function PhysicalMapButtonComponent(canvas:Object):void {
			this.canvas = canvas;
			// Init des visuels du composant			
			initGraphics();
			// Init des events du composant
			initEvents();	
			// Init des process du composant
			initProcess();
		}
		
		
		private function initGraphics():void {
			clickgrabber.graphics.lineStyle(4,0xFFFFFF, 1);
			clickgrabber.graphics.beginFill(0xFFFFFF, 0.5);
			clickgrabber.graphics.drawCircle(0, 0, 45);
			clickgrabber.graphics.endFill();
			this.addChild(clickgrabber);
			
			var format:TextFormat= new TextFormat();
			format.font= "myFont";
			format.color= 0xFFFFFF;
			format.size = 30;
						
			this.t = new TextField();
			this.t.background = false;	
			this.t.alpha = 1;
			this.t.embedFonts = true;
			this.t.selectable  = false;		 
			this.t.text = "Physical map";
			this.t.autoSize = TextFieldAutoSize.LEFT;
			this.t.x = 50;
			this.t.y = -15;
			this.t.setTextFormat(format);
			this.addChild(this.t);
			
			var imageLoader:Loader =new Loader();
			imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,resfreshIconLoadComplete);
			imageLoader.load(new URLRequest("../resources/websearch.png"));
		}
		
		private function initProcess():void {
		}
		
		private function initEvents():void {
			this.addEventListener(TouchEvent.MOUSE_DOWN, this.doNormalMap);
		}
		
		private function resfreshIconLoadComplete(event:Event):void {
			var resfreshIcon:Bitmap = new Bitmap();
			resfreshIcon.bitmapData = event.target.content.bitmapData;
			resfreshIcon.alpha = 0.5;
			resfreshIcon.width = 60;
			resfreshIcon.height = 60;
			resfreshIcon.x = -30;
			resfreshIcon.y = -30;
			resfreshIcon.alpha = 1;
			this.addChild(resfreshIcon);			
		}
		
		private function doNormalMap(e:TouchEvent):void {
			if (this.canvas.getPhysicalMapLayer() != null) {
				this.canvas.doClosePhysicalMapLayer();
			} else {	
				this.canvas.doDisplayPhysicalMapLayer(0x220099);
			}
		}
		
	}
	
}